package recompiled;

/**
 * TARGET PC: 0xA000001C
 */
public class A000001C extends compiler.BasicBlock {

	private static final A000001C INSTANCE = new A000001C();

	private A000001C(){}

	/**
	 * @see compiler.BasicBlock#getBasicBlock 
	 */
	public static compiler.BasicBlock getBasicBlock() {
		return INSTANCE;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void execute() throws mips.exceptions.MipsException {

		//0xa000001c 
		//0x8fbf0014 
		//LW
		mips.CPU.GPR[31] = n64.MemoryManager.readWord(mips.CPU.GPR[29] + 20);
		
		mips.CPU.PC = mips.CPU.nPC;
		mips.CPU.nPC = mips.CPU.PC + 4;


		//0xa0000020 
		//0x8fbe0010 
		//LW
		mips.CPU.GPR[30] = n64.MemoryManager.readWord(mips.CPU.GPR[29] + 16);
		
		mips.CPU.PC = mips.CPU.nPC;
		mips.CPU.nPC = mips.CPU.PC + 4;


		//0xa0000024 
		//0x27bd0020 
		//ADDIU
		u32_gpr_rs = mips.instructions.Instruction.zeroExtendW(mips.CPU.GPR[29]); 
		
		mips.CPU.GPR[29] = (int)((u32_gpr_rs + 32) & 4294967295L);
		
		mips.CPU.PC = mips.CPU.nPC;
		mips.CPU.nPC = mips.CPU.PC + 4;


		//0xa0000028 
		//0x0800000a 
		//J
		mips.CPU.PC = mips.CPU.nPC;
		mips.CPU.nPC = (mips.CPU.nPC & 0xF0000000) | 0x00000028;


		if(!skipDelaySlot) {
			//0xa000002c 
			//0x00000020 
			//NOP
			mips.CPU.PC = mips.CPU.nPC;
			mips.CPU.nPC = mips.CPU.PC + 4;
		}
	}

	public static int instructionLength = 5;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int blockLength() {
		int returnLen = instructionLength;
		if(skipDelaySlot) {
			returnLen -= 1;
			skipDelaySlot = false;
		}
		return returnLen;
	}
}

